package com.moleq.mgnetwork;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.moleq.db.DatabaseSchema;
import com.moleq.db.DatabaseSchema.StoreSetting;
import com.moleq.network.CommTask;
import com.moleq.network.Constant;
import com.moleq.util.SecurityUtil;
import com.moleq.util.ServiceUtil;

public class MgnetworkTool {
	private SQLiteDatabase db;

	public String action = "";
	public String tableName = "";
	public String record = "";
	public String deleteType = "";
	public List<String> data;
	public List<String> extraFiles;
    public  com.moleq.network.StoreSetting mStoreSetting;
    public String macAddress;
    
	public String getMacAddress() {
		return macAddress;
	}

	public void setMacAddress(String macAddress) {
		this.macAddress = macAddress;
	}

	public void reset() {
		action = "";
		tableName = "";
		record = "";
		deleteType = "";
	}

	public void parseRecordString(String detail) {
		System.out.println("---> start");
		// detail =
		// "Insert|t_item_setting|('000000000001','TEST ITEM 1 Tm
		// .',1,0,'A',10,'48',10.5,'','测试货品 1',
		// 2.88,1,0.0,'0','0','0','0','0','20120222020222','20121010073633','0','0','0','0','0','0','0',0,'0','0','0','0')";
		String temp[] = detail.split("\\|");
		action = temp[0];
		tableName = temp[1];
		record = temp[2];
		if (temp.length > 3) {
			deleteType = temp[3];
		}
		System.out.println("---> record " +record);
		data = ServiceUtil.parseSqlRecord(record.substring(1, (record.length() - 1)));
		System.out.println("---> data size "+ data.size());
	}


	public String[] getColumnsByTable(String tableName) {
		String[] result = null;
		if (tableName.equals(DatabaseSchema.ItemSetting.SCHEMA_NAME)) {
			if (action.equals("GLOBALPRICE")) {
				result = GlobalPriceStructure();
			}else{
				result = ItemSettingDBStructure();
			}
		} else if (tableName.equals(DatabaseSchema.FlipChart.SCHEMA_NAME)) {
			result = FlipChartSettingDBStructure();
		} else if (tableName.equals(DatabaseSchema.FunctionPanel.SCHEMA_NAME)) {
			result = FunctionPanelDBStructure();
		} else if (tableName
				.equals(DatabaseSchema.ItemDiscountSetting.SCHEMA_NAME)) {
			result = ItemDiscountSettingDBStructure();
		} else if (tableName
				.equals(DatabaseSchema.GLobalDiscountSetting.SCHEMA_NAME)) {
			result = GlobalDiscountSettingDBStructure();
		} else if (tableName.equals(DatabaseSchema.StoreSetting.SCHEMA_NAME)) {
			result = StoreSettingDBStructure();
		} else if (tableName.equals(DatabaseSchema.TaxSetting.SCHEMA_NAME)) {
			result = TaxSettingDBStructure();
		} else if (tableName.equals(DatabaseSchema.TareSetting.SCHEMA_NAME)) {
			result = TareSettingDBStructure();
		} else if (tableName.equals(DatabaseSchema.BottleSetting.SCHEMA_NAME)) {
			result = BottleSettingDBStructure();
		} else if (tableName.equals(DatabaseSchema.Receipt.SCHEMA_NAME)) {
			result = ReceiptDBStructure();
		} else if (tableName.equals(DatabaseSchema.PosSetting.SCHEMA_NAME)) {
			result = PosSettingDBStructure();
		} else if (tableName.equals(DatabaseSchema.PriceSetting.SCHEMA_NAME)) {
			result = PriceSettingDBStructure();
		} else if (tableName.equals(DatabaseSchema.MixMatch.SCHEMA_NAME)) {
			result = MixMatchDBStructure();
		} else if (tableName.equals(DatabaseSchema.AgeSetting.SCHEMA_NAME)) {
			result = AgeSettingDBStructure();
		} else if (tableName.equals(DatabaseSchema.SecuritySetting.SCHEMA_NAME)) {
			result = SecuritySettingDBStructure();
		} else if (tableName
				.equals(DatabaseSchema.DepartmentSetting.SCHEMA_NAME)) {
			result = DepartmentSettingDBStructure();
		} else if (tableName.equals(DatabaseSchema.SubDeptSetting.SCHEMA_NAME)) {
			result = SubDeptSettingDBStructure();
		} else if (tableName.equals(DatabaseSchema.DeptGroup.SCHEMA_NAME)) {
			result = DeptGroupDBStructure();
		} else if (tableName.equals(DatabaseSchema.NetWorkSetting.SCHEMA_NAME)) {
			result = NetWorkSettingDBStructure();
		} else if (tableName.equals(DatabaseSchema.MixMatchSetting.SCHEMA_NAME)) {
			result = MixMatchSettingDBStructure();
		} else if (tableName.equals(DatabaseSchema.UserSetting.SCHEMA_NAME)) {
			result = UserSettingDBStructure();
		} else if (tableName.equals(DatabaseSchema.ItemTareSetting.SCHEMA_NAME)) {
			result = ItemTareSettingDBStructure();
		} else if (tableName.equals(DatabaseSchema.CustomerSetting.SCHEMA_NAME)) {
			result = CustomerSettingDBStructure();
		}else if (tableName.equals(DatabaseSchema.ItemPic.SCHEMA_NAME)) {
			result = ItemPicDBStructure();
		}else if (tableName.equals(DatabaseSchema.InventorySetting.SCHEMA_NAME)) {
			result = InventorySetting();
		}else if(tableName.equals("t_item_sales")){
			result = stock_item_sales_fileds;
		}else if (tableName.equals(DatabaseSchema.PrinterSetting.SCHEMA_NAME)) {
			result = PrinterSettingDBStructure();
		}else if (tableName.equals(DatabaseSchema.RoundingSetting.SCHEMA_NAME)) {
			result = RoundingSettingDBStructure();
		}else if (tableName.equals(DatabaseSchema.DvrSetting.SCHEMA_NAME)) {
			result = DVRSettingDBStructure();
		}else if (tableName.equals(DatabaseSchema.MultCouponSetting.SCHEMA_NAME)){
			result = MultCouponSettingDBStructure();
		}else if (tableName.equals(DatabaseSchema.RegKey.SCHEMA_NAME)){
			result = RegKeyDBStructure();
		}
		
		return result;
	}
	
	private String[] stock_item_sales_fileds = {
			"is_id",
			"is_store_id",
			"is_station",
			"is_trn_no",
			"is_date",
			"is_upc_plu",
			"is_qty",
			"is_weight",
			"is_wt_unit",
			"is_amt"
	};
	
	public String[] ItemPicDBStructure(){
		String column[] = new String[]{
				DatabaseSchema.ItemPic.UPC,
				DatabaseSchema.ItemPic.IP_IMAGE,
				DatabaseSchema.ItemPic.IP_IMAGE_SM};
		return column;
	}
	
	public String[] GlobalPriceStructure(){
		String column[] = new String[]{
				DatabaseSchema.ItemSetting.UNIT_PRICE,
				DatabaseSchema.ItemSetting.DEPARTMENT_NUMBER
				};
		return column;
	}

	
	public String[] ItemSettingDBStructure() {
		String column[] = new String[] { DatabaseSchema.ItemSetting.ITEM_UPC,
				DatabaseSchema.ItemSetting.DESCRIPTOR,
				DatabaseSchema.ItemSetting.DEPARTMENT_NUMBER,
				DatabaseSchema.ItemSetting.SUB_DEPARTMENT_NUMBER,
				DatabaseSchema.ItemSetting.ITEM_STATUS_INDICATOR,
				DatabaseSchema.ItemSetting.CASE_PACK_SIZE,
				DatabaseSchema.ItemSetting.UNIT_OF_MEASURE,
				DatabaseSchema.ItemSetting.UNIT_PRICE_FACTOR,
				DatabaseSchema.ItemSetting.VENDOR_NUMBER,
				DatabaseSchema.ItemSetting.EXPANDED_DESCRIPTION,
				DatabaseSchema.ItemSetting.UNIT_PRICE,
				DatabaseSchema.ItemSetting.CURRENT_PRICE_QTY,
				DatabaseSchema.ItemSetting.CASE_COST,
				DatabaseSchema.ItemSetting.FOOD_STAMP,
				DatabaseSchema.ItemSetting.TAX1,
				DatabaseSchema.ItemSetting.SCALE_OR_WEIGHT,
				DatabaseSchema.ItemSetting.WIC_ELIGIBLE,
				DatabaseSchema.ItemSetting.CVV_ELIGIBILITY,
				DatabaseSchema.ItemSetting.CREATE_DATETIME,
				DatabaseSchema.ItemSetting.UPDATE_DATETIME,
				DatabaseSchema.ItemSetting.FOLLOW_DEPARTMENT,
				DatabaseSchema.ItemSetting.TAX2,
				DatabaseSchema.ItemSetting.TAX3,
				DatabaseSchema.ItemSetting.TAX4,
				DatabaseSchema.ItemSetting.ITEM_DISCOUNT_FLAG,
				DatabaseSchema.ItemSetting.BOTTLE_DEPOSIT,
				DatabaseSchema.ItemSetting.IS_LOYALTY,
				DatabaseSchema.ItemSetting.IS_TARE,
				DatabaseSchema.ItemSetting.IS_AGE_VER,
				DatabaseSchema.ItemSetting.TAX5,
				DatabaseSchema.ItemSetting.TAX6,
				DatabaseSchema.ItemSetting.IS_COUPON,
				DatabaseSchema.ItemSetting.SERVICE_FL,
				DatabaseSchema.ItemSetting.PRINTER_ID,
				DatabaseSchema.ItemSetting.IS_MULT_COUPON };
		return column;
	}

	public String[] FlipChartSettingDBStructure() {
		String column[] = new String[] { DatabaseSchema.FlipChart.ID,
				DatabaseSchema.FlipChart.ITEM_UPC,
				DatabaseSchema.FlipChart.GROUP, DatabaseSchema.FlipChart.ORDER,
				DatabaseSchema.FlipChart.CREATE_DATETIME,
				DatabaseSchema.FlipChart.UPDATE_DATETIME };
		return column;
	}

	public String[] FunctionPanelDBStructure() {
		String column[] = new String[] { DatabaseSchema.FunctionPanel.TP_NO,
				DatabaseSchema.FunctionPanel.TP_ORDER,
				DatabaseSchema.FunctionPanel.TP_FUNC_KEY,
				DatabaseSchema.FunctionPanel.TP_LABEL_FILE,
				DatabaseSchema.FunctionPanel.TP_APPL_FL,
				DatabaseSchema.FunctionPanel.TP_PARAMETER1,
				DatabaseSchema.FunctionPanel.TP_PARAMETER2,
				DatabaseSchema.FunctionPanel.CREATE_DATETIME,
				DatabaseSchema.FunctionPanel.UPDATE_DATETIME,
				DatabaseSchema.FunctionPanel.TP_PARAMETER3,
				DatabaseSchema.FunctionPanel.TP_LABEL_FILE2 };
		return column;
	}

	public String[] ItemDiscountSettingDBStructure() {
		String column[] = new String[] {
				DatabaseSchema.ItemDiscountSetting.DS_NO,
				DatabaseSchema.ItemDiscountSetting.DS_DESC,
				DatabaseSchema.ItemDiscountSetting.DS_TYPE,
				DatabaseSchema.ItemDiscountSetting.DS_VALUE,
				DatabaseSchema.ItemDiscountSetting.CREATE_TIME,
				DatabaseSchema.ItemDiscountSetting.UPDATE_TIME,
				DatabaseSchema.ItemDiscountSetting.DS_FOLLOW_ITEM,
				DatabaseSchema.ItemDiscountSetting.DS_TAX1,
				DatabaseSchema.ItemDiscountSetting.DS_TAX2,
				DatabaseSchema.ItemDiscountSetting.DS_TAX3,
				DatabaseSchema.ItemDiscountSetting.DS_TAX4,
				DatabaseSchema.ItemDiscountSetting.DS_TAX5,
				DatabaseSchema.ItemDiscountSetting.DS_TAX6,
				DatabaseSchema.ItemDiscountSetting.DS_FOODSTAMP };
		return column;
	}

	public String[] GlobalDiscountSettingDBStructure() {
		String column[] = new String[] {
				DatabaseSchema.GLobalDiscountSetting.GD_NO,
				DatabaseSchema.GLobalDiscountSetting.GD_DESC,
				DatabaseSchema.GLobalDiscountSetting.GD_VALUE,
				DatabaseSchema.GLobalDiscountSetting.CREATE_TIME,
				DatabaseSchema.GLobalDiscountSetting.UPDATE_TIME };
		return column;
	}

	public String[] StoreSettingDBStructure() {
		String column[] = new String[] { DatabaseSchema.StoreSetting.SS_ID,
				DatabaseSchema.StoreSetting.SS_NAME,
				DatabaseSchema.StoreSetting.SS_OTHER_NAME,
				DatabaseSchema.StoreSetting.SS_ADDRESS_1,
				DatabaseSchema.StoreSetting.SS_ADDRESS_2,
				DatabaseSchema.StoreSetting.SS_CITY,
				DatabaseSchema.StoreSetting.SS_STATE,
				DatabaseSchema.StoreSetting.SS_ZIP,
				DatabaseSchema.StoreSetting.SS_TELEPHONE,
				DatabaseSchema.StoreSetting.SS_FAX,
				DatabaseSchema.StoreSetting.SS_WEBSITE,
				DatabaseSchema.StoreSetting.CREATE_DATETIME,
				DatabaseSchema.StoreSetting.UPDATE_DATETIME,
				DatabaseSchema.StoreSetting.SS_BUSINESS_NAME};
		return column;
	}

	public String[] TaxSettingDBStructure() {
		String column[] = new String[] { DatabaseSchema.TaxSetting.TX_NO,
				DatabaseSchema.TaxSetting.TX_RATE,
				DatabaseSchema.TaxSetting.TX_START_AMT,
				DatabaseSchema.TaxSetting.TX_PLUS_ROUND,
				DatabaseSchema.TaxSetting.TX_VAT,
				DatabaseSchema.TaxSetting.TX_BY_LINE,
				DatabaseSchema.TaxSetting.CREATE_TIME,
				DatabaseSchema.TaxSetting.UPDATE_TIME };
		return column;
	}

	public String[] TareSettingDBStructure() {
		String column[] = new String[] { DatabaseSchema.TareSetting.TA_NO,
				DatabaseSchema.TareSetting.TA_DESC,
				DatabaseSchema.TareSetting.TA_VALUE,
				DatabaseSchema.TareSetting.CREATE_TIME,
				DatabaseSchema.TareSetting.UPDATE_TIME };
		return column;
	}

	public String[] BottleSettingDBStructure() {
		String column[] = new String[] { DatabaseSchema.BottleSetting.BO_NO,
				DatabaseSchema.BottleSetting.BO_DESC,
				DatabaseSchema.BottleSetting.BO_AMT,
				DatabaseSchema.BottleSetting.CREATE_TIME,
				DatabaseSchema.BottleSetting.UPDATE_TIME,
				DatabaseSchema.BottleSetting.BO_ENVF_FLAG,
				DatabaseSchema.BottleSetting.BO_ENVF_AMT,
				DatabaseSchema.BottleSetting.BO_ENVF_TAX1,
				DatabaseSchema.BottleSetting.BO_ENVF_TAX2,
				DatabaseSchema.BottleSetting.BO_ENVF_TAX3,
				DatabaseSchema.BottleSetting.BO_ENVF_TAX4,
				DatabaseSchema.BottleSetting.BO_ENVF_TAX5,
				DatabaseSchema.BottleSetting.BO_ENVF_TAX6,
				DatabaseSchema.BottleSetting.BO_ENVF_FS,
				DatabaseSchema.BottleSetting.BO_ENVF_WIC };
		return column;
	}

	public String[] ReceiptDBStructure() {
		String column[] = new String[] { DatabaseSchema.Receipt.RM_ID,
				DatabaseSchema.Receipt.RM_TYPE, DatabaseSchema.Receipt.RM_MSG,
				DatabaseSchema.Receipt.CREATE_TIME,
				DatabaseSchema.Receipt.UPDATE_TIME,
				DatabaseSchema.Receipt.RM_LARGE,
				DatabaseSchema.Receipt.RM_JUSTIFY };
		return column;
	}

	public String[] PosSettingDBStructure() {
		String column[] = new String[] { DatabaseSchema.PosSetting.ID,
				DatabaseSchema.PosSetting.OPEN_TIME,
				DatabaseSchema.PosSetting.CLOSE_TIME,
				DatabaseSchema.PosSetting.TARE_RATE,
				DatabaseSchema.PosSetting.FILPCHART_MAX,
				DatabaseSchema.PosSetting.CREATE_DATETIME,
				DatabaseSchema.PosSetting.UPDATE_DATETIME,
				DatabaseSchema.PosSetting.PS_WEIGHT_UNIT,
				DatabaseSchema.PosSetting.STORE_NO,
				DatabaseSchema.PosSetting.PRICE_DIGITS,
				DatabaseSchema.PosSetting.CURRENCY_SIGN,
				DatabaseSchema.PosSetting.CALCULATE_WEIGHT,
				DatabaseSchema.PosSetting.CALENDAR_TYPE,
				DatabaseSchema.PosSetting.NORM_UPCE,
				DatabaseSchema.PosSetting.SHOW_DESC,
				DatabaseSchema.PosSetting.ZERO_BALN,
				DatabaseSchema.PosSetting.ZERO_PRICE,
				DatabaseSchema.PosSetting.FS_TAX_RULE,
				DatabaseSchema.PosSetting.PRCTAG_PRINTER,
				DatabaseSchema.PosSetting.ROUNDING,
				DatabaseSchema.PosSetting.PRINT_SERVICE,
				DatabaseSchema.PosSetting.SIG_HOST,
				DatabaseSchema.PosSetting.SIG_LOCAL,
				DatabaseSchema.PosSetting.SIG_MIN,
				DatabaseSchema.PosSetting.RECEIPT_PNT};
		return column;
	}

	public String[] PriceSettingDBStructure() {
		String column[] = new String[] { DatabaseSchema.PriceSetting.ITEM_UPC,
				DatabaseSchema.PriceSetting.PRICE_MULTIPLE,
				DatabaseSchema.PriceSetting.PRICE,
				DatabaseSchema.PriceSetting.STAR_TDATE,
				DatabaseSchema.PriceSetting.STAR_TTIME,
				DatabaseSchema.PriceSetting.END_DATE,
				DatabaseSchema.PriceSetting.END_TIME,
				DatabaseSchema.PriceSetting.PACKAGEPRICE_MULTIPLE,
				DatabaseSchema.PriceSetting.PACKAGE_PRICE,
				DatabaseSchema.PriceSetting.LIMITEDQTY_AMOUNT,
				DatabaseSchema.PriceSetting.LIMITEDQTY_PRICE,
				DatabaseSchema.PriceSetting.DISCOUNT_AMOUNT,
				DatabaseSchema.PriceSetting.DISCOUNT_PERCENT,
				DatabaseSchema.PriceSetting.PRICE_MM,
				DatabaseSchema.PriceSetting.CREATE_DATETIME,
				DatabaseSchema.PriceSetting.UPDATE_DATETIME,
				DatabaseSchema.PriceSetting.DISCOUNT_LINK };
		return column;
	}

	public String[] MixMatchDBStructure() {
		String column[] = new String[] { DatabaseSchema.MixMatch.MM_NO,
				DatabaseSchema.MixMatch.UPC };
		return column;
	}

	public String[] AgeSettingDBStructure() {
		String column[] = new String[] { DatabaseSchema.AgeSetting.AS_NO,
				DatabaseSchema.AgeSetting.AS_DESC,
				DatabaseSchema.AgeSetting.AS_AGE,
				DatabaseSchema.AgeSetting.CREATE_TIME,
				DatabaseSchema.AgeSetting.UPDATE_TIME };
		return column;
	}

	public String[] SecuritySettingDBStructure() {
		String column[] = new String[] { DatabaseSchema.SecuritySetting.SC_ID,
				DatabaseSchema.SecuritySetting.SC_USER_ID,
				DatabaseSchema.SecuritySetting.SC_FUNC_ID };
		return column;
	}

	public String[] DepartmentSettingDBStructure() {
		String column[] = new String[] {
				DatabaseSchema.DepartmentSetting.DEPARTMENT_NO,
				DatabaseSchema.DepartmentSetting.DEPARTMENT_NAME,
				DatabaseSchema.DepartmentSetting.DEPARTMENT_TAX1,
				DatabaseSchema.DepartmentSetting.DEPARTMENT_FOOD_STAMP,
				DatabaseSchema.DepartmentSetting.CREATE_DATETIME,
				DatabaseSchema.DepartmentSetting.UPDATE_DATETIME,
				DatabaseSchema.DepartmentSetting.DEPARTMENT_TAX2,
				DatabaseSchema.DepartmentSetting.DEPARTMENT_TAX3,
				DatabaseSchema.DepartmentSetting.DEPARTMENT_TAX4,
				DatabaseSchema.DepartmentSetting.SCALABLE,
				DatabaseSchema.DepartmentSetting.WIC,
				DatabaseSchema.DepartmentSetting.NO_DISCOUNT,
				DatabaseSchema.DepartmentSetting.CVV,
				DatabaseSchema.DepartmentSetting.DEPARTMENT_GROUP,
				DatabaseSchema.DepartmentSetting.ds_AGE_VER,
				DatabaseSchema.DepartmentSetting.DEPARTMENT_TAX5,
				DatabaseSchema.DepartmentSetting.DEPARTMENT_TAX6 };
		return column;
	}

	public String[] SubDeptSettingDBStructure() {
		String column[] = new String[] { DatabaseSchema.SubDeptSetting.SD_ID,
				DatabaseSchema.SubDeptSetting.SD_NAME,
				DatabaseSchema.SubDeptSetting.DEPARTMENT_TAX1,
				DatabaseSchema.SubDeptSetting.DEPARTMENT_FOOD_STAMP,
				DatabaseSchema.SubDeptSetting.DEPARTMENT_TAX2,
				DatabaseSchema.SubDeptSetting.DEPARTMENT_TAX3,
				DatabaseSchema.SubDeptSetting.DEPARTMENT_TAX4,
				DatabaseSchema.SubDeptSetting.SCALABLE,
				DatabaseSchema.SubDeptSetting.WIC,
				DatabaseSchema.SubDeptSetting.NO_DISCOUNT,
				DatabaseSchema.SubDeptSetting.CVV,
				DatabaseSchema.SubDeptSetting.DEPARTMENT_NO,
				DatabaseSchema.SubDeptSetting.SD_AGE_VER,
				DatabaseSchema.SubDeptSetting.DEPARTMENT_TAX5,
				DatabaseSchema.SubDeptSetting.DEPARTMENT_TAX6,
				DatabaseSchema.SubDeptSetting.CREATE_DATETIME,
				DatabaseSchema.SubDeptSetting.UPDATE_DATETIME };
		return column;
	}

	public String[] DeptGroupDBStructure() {
		String column[] = new String[] { DatabaseSchema.DeptGroup.DG_NO,
				DatabaseSchema.DeptGroup.DG_NAME,
				DatabaseSchema.DeptGroup.CREATE_TIME,
				DatabaseSchema.DeptGroup.UPDATE_TIME };
		return column;
	}

	public String[] NetWorkSettingDBStructure() {
		String column[] = new String[] { DatabaseSchema.NetWorkSetting.NS_NO,
				DatabaseSchema.NetWorkSetting.NS_STATION,
				DatabaseSchema.NetWorkSetting.NS_NAME,
				DatabaseSchema.NetWorkSetting.NS_IP,
				DatabaseSchema.NetWorkSetting.NS_TYPE,
				DatabaseSchema.NetWorkSetting.CREATE_TIME,
				DatabaseSchema.NetWorkSetting.UPDATE_TIME };
		return column;
	}

	public String[] MixMatchSettingDBStructure() {
		String column[] = new String[] { DatabaseSchema.MixMatchSetting.MS_NO,
				DatabaseSchema.MixMatchSetting.DESCRIPTION,
				DatabaseSchema.MixMatchSetting.PRICE_MULTIPLE,
				DatabaseSchema.MixMatchSetting.PRICE,
				DatabaseSchema.MixMatchSetting.START_DATE,
				DatabaseSchema.MixMatchSetting.START_TIME,
				DatabaseSchema.MixMatchSetting.END_DATE,
				DatabaseSchema.MixMatchSetting.END_TIME,
				DatabaseSchema.MixMatchSetting.PACKAGEPRICE_MULTIPLE,
				DatabaseSchema.MixMatchSetting.PACKAGE_PRICE,
				DatabaseSchema.MixMatchSetting.LIMITEDQTY_AMOUNT,
				DatabaseSchema.MixMatchSetting.LIMITEDQTY_PRICE,
				DatabaseSchema.MixMatchSetting.DISCOUNT_AMOUNT,
				DatabaseSchema.MixMatchSetting.DISCOUNT_PERCENT,
				DatabaseSchema.MixMatchSetting.CREATE_TIME,
				DatabaseSchema.MixMatchSetting.UPDATE_TIME,
				DatabaseSchema.MixMatchSetting.DISCOUNT_LINK };
		return column;
	}

	public String[] UserSettingDBStructure() {
		String column[] = new String[] { DatabaseSchema.UserSetting.ID,
				DatabaseSchema.UserSetting.LOGIN_ID,
				DatabaseSchema.UserSetting.PASSWORD,
				DatabaseSchema.UserSetting.INFO,
				DatabaseSchema.UserSetting.ACTIVE,
				DatabaseSchema.UserSetting.COLOR,
				DatabaseSchema.UserSetting.MANAGER };
		return column;
	}

	public String[] ItemTareSettingDBStructure() {
		String column[] = new String[] { // DatabaseSchema.ItemTareSetting.IT_NO,
		DatabaseSchema.ItemTareSetting.UPC,
				DatabaseSchema.ItemTareSetting.IT_TARE_NO,
				DatabaseSchema.ItemTareSetting.CREATE_TIME,
				DatabaseSchema.ItemTareSetting.UPDATE_TIME };
		return column;
	}

	public String[] CustomerSettingDBStructure() {
		String column[] = new String[] { DatabaseSchema.CustomerSetting.CS_NO,
				DatabaseSchema.CustomerSetting.CS_LAST_NAME,
				DatabaseSchema.CustomerSetting.CS_FIRST_NAME,
				DatabaseSchema.CustomerSetting.CS_ADDRESS_1,
				DatabaseSchema.CustomerSetting.CS_ADDRESS_2,
				DatabaseSchema.CustomerSetting.CS_CITY,
				DatabaseSchema.CustomerSetting.CS_STATE,
				DatabaseSchema.CustomerSetting.CS_ZIP,
				DatabaseSchema.CustomerSetting.CS_TELEPHONE,
				DatabaseSchema.CustomerSetting.CS_EMAIL,
				DatabaseSchema.CustomerSetting.CREATE_DATETIME,
				DatabaseSchema.CustomerSetting.UPDATE_DATETIME };
		return column;
	}
	
	public String[] InventorySetting(){
		String column[] = new String[] { 
				DatabaseSchema.InventorySetting.IS_ID,
				DatabaseSchema.InventorySetting.IS_ONOFF,
				DatabaseSchema.InventorySetting.IS_SERVER_IP };
		return column;
	}
	
	public String[] PrinterSettingDBStructure() {
		String column[] = new String[] { DatabaseSchema.PrinterSetting.PS_ID,
				DatabaseSchema.PrinterSetting.PS_NAME,
				DatabaseSchema.PrinterSetting.PS_IP,
				DatabaseSchema.PrinterSetting.PS_PORT};
		return column;
	}
	
	public String[] RoundingSettingDBStructure() {
		String column[] = new String[] { DatabaseSchema.RoundingSetting.RS_ID,
				DatabaseSchema.RoundingSetting.RS_NAME,
				DatabaseSchema.RoundingSetting.RS_DOWN_VALUE,
				DatabaseSchema.RoundingSetting.RS_UP_VALUE,
				DatabaseSchema.RoundingSetting.RS_TO_VALUE,
				DatabaseSchema.RoundingSetting.RS_OPTIONAL};
		return column;
	}
	
	public String[] DVRSettingDBStructure() {
		String column[] = new String[] { DatabaseSchema.DvrSetting.DS_ID,
				DatabaseSchema.DvrSetting.DS_ONOFF,
				DatabaseSchema.DvrSetting.DS_DVR_IP,
				DatabaseSchema.DvrSetting.DS_PORT};
		return column;
	}
	
	public String[] MultCouponSettingDBStructure() {
		String column[] = new String[] { DatabaseSchema.MultCouponSetting.MC_ID,
				DatabaseSchema.MultCouponSetting.MC_ACTIVE,
				DatabaseSchema.MultCouponSetting.MC_CPN_NAME,
				DatabaseSchema.MultCouponSetting.MC_MULT,
				DatabaseSchema.MultCouponSetting.MC_ADD_VALUE,
				DatabaseSchema.MultCouponSetting.MC_MAX_VALUE,
				DatabaseSchema.MultCouponSetting.MC_MAX_TOTAL,
				DatabaseSchema.MultCouponSetting.CREATE_DATETIME,
				DatabaseSchema.MultCouponSetting.UPDATE_DATETIME};
		return column;
		
	}
	
	public String[] RegKeyDBStructure() {
		String column[] = new String[] { DatabaseSchema.RegKey.RK_CODE,
				DatabaseSchema.RegKey.RK_KEY};
		return column;
	}
	// ////
	public boolean isExist(String tbName, String strWhere) {
		boolean result = false;

		String sql = " SELECT count(*) FROM " + tbName + " WHERE %s ";
		sql = String.format(sql, strWhere);

		System.out.println("---> tool -> commit -> insert or update ->  isexist -> sql"
						+ sql);
		long count = 0;
		Cursor cursor = db.rawQuery(sql, null);

		System.out
				.println("---> tool -> commit -> insert or update ->  isexist -> cursor");

		cursor.moveToFirst();
		count = cursor.getLong(0);
		
		System.out
		.println("---> tool -> commit -> insert or update ->  isexist -> count = " + count);

		cursor.close();

		if (count > 0)
			result = true;

		return result;
	}

	public String createInsert(String tableName, String column[],
			List<String> data) {
		String sql = "INSERT INTO " + tableName + "(";
		for (int i = 0; i < column.length; i++) {
			sql += column[i] + ",";
		}
		sql = sql.substring(0, sql.length() - 1) + ") VALUES(";
		for (int i = 0; i < data.size(); i++) {
			sql += data.get(i) + ",";
		}
		sql = sql.substring(0, sql.length() - 1) + ")";
		return sql;
	}

	public String createUpdate(String tableName, String column[],
			List<String> data) {
		String sql = "UPDATE " + tableName + " SET ";
		for (int i = 0; i < column.length; i++) {
			sql += column[i] + " = " + data.get(i) + ",";
		}
		sql = sql.substring(0, sql.length() - 1) + " where "
				+ createWhere(tableName);
		return sql;
	}
	
	public String createUpdateGlobalPrice(String tableName,
			List<String> data) {
		String sql = "UPDATE " + tableName + " SET ";
//		for (int i = 0; i < column.length; i++) {
			sql += "F30 = ROUND("+data.get(0)+", 2) ";
//		}
		sql = sql.substring(0, sql.length() - 1) + " where "
				+ createWhere(tableName);
		return sql;
	}

	public String createDelete(String tableName) {
		String sql = "DELETE FROM " + tableName + " WHERE %s";
		sql = String.format(sql, createWhere(tableName));
		return sql;
	}

	public void opendb(String dbPath) {
		db = SQLiteDatabase.openOrCreateDatabase(dbPath, null);

	}

	public void closedb() {
		if (db != null) {
			db.close();
		}
	}

	public boolean execSql(String sql) {
		boolean result = false;
		try {
			db.execSQL(sql);
			result = true;
		} catch (Exception e) {
			// TODO: handle exception
			result = false;
		}
		return result;
	}

	public Cursor rawQuery(String sql) {
		Cursor cursor = db.rawQuery(sql, null);
		return cursor;
	}

		
	public boolean commit() {
		System.out.println("---> tool -> commit ->");
		boolean result = false;
		String sql = "";
		if (action.equals("DELETE")) {
			sql = createDelete(tableName);
		}else if (action.equals("UPDATE") || action.equals("INSERT")) {
			System.out.println("---> tool -> commit -> insert or update -> ");

//			System.out.println("table row is exist ->" + isExist(tableName, createWhere(tableName)));
			
			if(tableName.equals("t_item_sales")){
				sql = createInsert(tableName, getColumnsByTable(tableName), data);
				
			}else{
				if (isExist(tableName, createWhere(tableName))) {

					if (tableName.equals(DatabaseSchema.ItemPic.SCHEMA_NAME)) {
						byte[] b1 = null;
						byte[] b2 = null;
						String tmpfile;
						File imgFile1, imgFile2;

						tmpfile = ServiceUtil.getTagValue(data.get(1), "file");
						System.out.println(">>>>>>> start save image <<<<<<<<");
						tmpfile = ServiceUtil.getTagValue(data.get(1), "file");
						imgFile1 = new File(Constant.SDCARD_IN_BOX + tmpfile);
						if (imgFile1.exists()) {
							System.out.println("--->> " + imgFile1.getAbsoluteFile() + " is exist.");

							b1 = ServiceUtil.convertImageFile2Bytes("" + imgFile1.getAbsoluteFile());

						}

						tmpfile = ServiceUtil.getTagValue(data.get(2), "file");
						imgFile2 = new File(Constant.SDCARD_IN_BOX + tmpfile);
						if (imgFile2.exists()) {
							System.out.println("--->> " + imgFile2.getAbsoluteFile() + " is exist.");

							b2 = ServiceUtil.convertImageFile2Bytes("" + imgFile2.getAbsoluteFile());

						}

						if (b1 != null && b2 != null) {
							String tmpUpc = data.get(0).replace("'", "");

							ImageUpdate(tmpUpc, b1, b2);
							System.out.println(" succeed update image.");
							
							if (imgFile1.exists()) imgFile1.delete();
							if (imgFile2.exists()) imgFile2.delete();
						}

						System.out.println(">>>>>>> end save image <<<<<<<<");
						// ImageUpdate(data.get(0),data.get(1).getBytes(),data.get(2).getBytes());
						sql = "";
					} else {
						sql = createUpdate(tableName, getColumnsByTable(tableName), data);
					}
				}else {
					if (tableName.equals(DatabaseSchema.ItemPic.SCHEMA_NAME)) {
						byte[] b1 = null;
						byte[] b2 = null;
						String tmpfile;
						File imgFile1, imgFile2;

						tmpfile = ServiceUtil.getTagValue(data.get(1), "file");
						System.out.println(">>>>>>> start save image <<<<<<<<");
						tmpfile = ServiceUtil.getTagValue(data.get(1), "file");
						imgFile1 = new File(Constant.SDCARD_IN_BOX + tmpfile);
						if (imgFile1.exists()) {
							System.out.println("--->> " + imgFile1.getAbsoluteFile() + " is exist.");
							b1 = ServiceUtil.convertImageFile2Bytes("" + imgFile1.getAbsoluteFile());

						}

						tmpfile = ServiceUtil.getTagValue(data.get(2), "file");
						imgFile2 = new File(Constant.SDCARD_IN_BOX + tmpfile);
						if (imgFile2.exists()) {
							System.out.println("--->> " + imgFile2.getAbsoluteFile() + " is exist.");

							b2 = ServiceUtil.convertImageFile2Bytes("" + imgFile2.getAbsoluteFile());

						}

						if (b1 != null && b2 != null) {
							String tmpUpc = data.get(0).replace("'", "");
							ImageInsert(tmpUpc, b1, b2);
							System.out.println(" succeed insert image.");
							
							if (imgFile1.exists()) imgFile1.delete();
							if (imgFile2.exists()) imgFile2.delete();
					
						}

						System.out.println(">>>>>>> end save image <<<<<<<<");
						
						// ImageUpdate(data.get(0),data.get(1).getBytes(),data.get(2).getBytes());
						sql = "";
						
					} else {
						sql = createInsert(tableName, getColumnsByTable(tableName), data);
					}
				}
			}
			
			
		}else if(action.equals("GLOBALPRICE")){
			sql = createUpdateGlobalPrice(tableName, data);
			System.out.println(">>>>>>>GLOBALPRICE sql <<<<<<<< "+sql);
		}

		System.out.println("---> call sql ->" + sql);
		if (!sql.equals("")) {
			result = execSql(sql);
		}
		System.out.println("---> execSql  -> " + result);

		this.reset();

		return result;
	}

//	private String createGlobalPrice(String tableName2,List<String> data2) {
//		// TODO Auto-generated method stub
//		String sql = "UPDATE " + tableName + " SET ";
////		for (int i = 0; i < column.length; i++) {
//			sql += "F30 = " + data.get(0) + ",";
////		}
//		sql = sql.substring(0, sql.length() - 1) + " where "
//				+ createWhere(tableName);
//		return sql;
//	}

	public String createWhere(String tableName) {
		if (tableName.equals(DatabaseSchema.ItemSetting.SCHEMA_NAME)) {
			if (action.equals("GLOBALPRICE")) {
				return DatabaseSchema.ItemSetting.DEPARTMENT_NUMBER +" = " +data.get(1);
			}else{
				return DatabaseSchema.ItemSetting.ITEM_UPC + " = " + data.get(0);
			}
			
		} else if (tableName.equals(DatabaseSchema.FlipChart.SCHEMA_NAME)) {
			return DatabaseSchema.FlipChart.ID + " = " + data.get(0);
		} else if (tableName.equals(DatabaseSchema.FunctionPanel.SCHEMA_NAME)) {
			return DatabaseSchema.FunctionPanel.TP_NO + " = " + data.get(0);
		} else if (tableName
				.equals(DatabaseSchema.ItemDiscountSetting.SCHEMA_NAME)) {
			return DatabaseSchema.ItemDiscountSetting.DS_NO + " = "
					+ data.get(0);
		} else if (tableName
				.equals(DatabaseSchema.GLobalDiscountSetting.SCHEMA_NAME)) {
			return DatabaseSchema.GLobalDiscountSetting.GD_NO + " = "
					+ data.get(0);
		} else if (tableName.equals(DatabaseSchema.StoreSetting.SCHEMA_NAME)) {
//			return DatabaseSchema.StoreSetting.SS_ID + " = " + data.get(0);
			return "1 = 1" ;
		} else if (tableName.equals(DatabaseSchema.TaxSetting.SCHEMA_NAME)) {
			return DatabaseSchema.TaxSetting.TX_NO + " = " + data.get(0);
		} else if (tableName.equals(DatabaseSchema.TareSetting.SCHEMA_NAME)) {
			return DatabaseSchema.TareSetting.TA_NO + " = " + data.get(0);
		} else if (tableName.equals(DatabaseSchema.BottleSetting.SCHEMA_NAME)) {
			return DatabaseSchema.BottleSetting.BO_NO + " = " + data.get(0);
		} else if (tableName.equals(DatabaseSchema.Receipt.SCHEMA_NAME)) {
			return DatabaseSchema.Receipt.RM_ID + " = " + data.get(0);
		} else if (tableName.equals(DatabaseSchema.PosSetting.SCHEMA_NAME)) {
			return DatabaseSchema.PosSetting.ID + " = " + data.get(0);
		} else if (tableName.equals(DatabaseSchema.PriceSetting.SCHEMA_NAME)) {
			return DatabaseSchema.PriceSetting.ITEM_UPC + " = " + data.get(0);
		} else if (tableName.equals(DatabaseSchema.MixMatch.SCHEMA_NAME)) {
			return DatabaseSchema.MixMatch.UPC + " = " + data.get(1);
		} else if (tableName.equals(DatabaseSchema.AgeSetting.SCHEMA_NAME)) {
			return DatabaseSchema.AgeSetting.AS_NO + " = " + data.get(0);
		} else if (tableName.equals(DatabaseSchema.UserSetting.SCHEMA_NAME)) {
			return DatabaseSchema.UserSetting.ID + " = " + data.get(0);
		} else if (tableName.equals(DatabaseSchema.SecuritySetting.SCHEMA_NAME)) {
			if (deleteType.equals("A")) {
				return DatabaseSchema.SecuritySetting.SC_USER_ID + " = "
						+ data.get(1);
			} else {
				return DatabaseSchema.SecuritySetting.SC_USER_ID + " = "
						+ data.get(1) + " and "
						+ DatabaseSchema.SecuritySetting.SC_FUNC_ID + " = "
						+ data.get(2);
			}
		} else if (tableName
				.equals(DatabaseSchema.DepartmentSetting.SCHEMA_NAME)) {
			return DatabaseSchema.DepartmentSetting.DEPARTMENT_NO + " = "
					+ data.get(0);
		} else if (tableName.equals(DatabaseSchema.SubDeptSetting.SCHEMA_NAME)) {
			return DatabaseSchema.SubDeptSetting.SD_ID + " = " + data.get(0);
		} else if (tableName.equals(DatabaseSchema.DeptGroup.SCHEMA_NAME)) {
			return DatabaseSchema.DeptGroup.DG_NO + " = " + data.get(0);
		} else if (tableName.equals(DatabaseSchema.NetWorkSetting.SCHEMA_NAME)) {
			return DatabaseSchema.NetWorkSetting.NS_STATION + " = " + data.get(1);		
		} else if (tableName.equals(DatabaseSchema.MixMatchSetting.SCHEMA_NAME)) {
			return DatabaseSchema.MixMatchSetting.MS_NO + " = " + data.get(0);
		} else if (tableName.equals(DatabaseSchema.ItemTareSetting.SCHEMA_NAME)) {
			if (action.equals("DELETE")) {
				return DatabaseSchema.ItemTareSetting.UPC + " = " + data.get(0);
			} else if (action.equals("INSERT")) {
				return DatabaseSchema.ItemTareSetting.UPC + " = " + data.get(0)
						+ " and " + DatabaseSchema.ItemTareSetting.IT_TARE_NO
						+ " = " + data.get(1);
			}
			// return DatabaseSchema.ItemTareSetting.UPC + " = " +
			// data.get(0) + " and "
			// + DatabaseSchema.ItemTareSetting.IT_TARE_NO + " = " +
			// data.get(1);
			// return "1 = 2";
			// } else {
			// return DatabaseSchema.ItemTareSetting.UPC + " = " + data.get(0)
			// + " and " + DatabaseSchema.ItemTareSetting.IT_TARE_NO
			// + " = " + data.get(1);
			// }
			// return DatabaseSchema.ItemTareSetting.IT_NO + " = " + data.get(0)
			// + " and " + DatabaseSchema.ItemTareSetting.UPC + " = "
			// + data.get(1);
		} else if (tableName.equals(DatabaseSchema.CustomerSetting.SCHEMA_NAME)) {
			return DatabaseSchema.CustomerSetting.CS_NO + " = " + data.get(0);
		} else if (tableName.equals(DatabaseSchema.ItemPic.SCHEMA_NAME)){
			return DatabaseSchema.ItemPic.UPC + " = " + data.get(0);
		}else if (tableName.equals(DatabaseSchema.InventorySetting.SCHEMA_NAME)){
			return DatabaseSchema.InventorySetting.IS_ID + " = " + data.get(0);
		}else if (tableName.equals(DatabaseSchema.PrinterSetting.SCHEMA_NAME)){
			return DatabaseSchema.PrinterSetting.PS_ID + " = " + data.get(0);
		}else if (tableName.equals(DatabaseSchema.RoundingSetting.SCHEMA_NAME)){
			return DatabaseSchema.RoundingSetting.RS_ID + " = " + data.get(0);
		}else if (tableName.equals(DatabaseSchema.DvrSetting.SCHEMA_NAME)){
			return DatabaseSchema.DvrSetting.DS_ID + " = " + data.get(0);
		} else if(tableName.equals("t_item_sales")){
			return " id = null ";
		}else if(tableName.equals(DatabaseSchema.MultCouponSetting.SCHEMA_NAME)){
			return DatabaseSchema.MultCouponSetting.MC_ID + " = " + data.get(0);
		}else if(tableName.equals(DatabaseSchema.RegKey.SCHEMA_NAME)){
			return " 1 = 1 ";
		}else{
			return " 1 = 1 ";
		}
		return tableName;
	}

	public boolean isValidAction() {
		if (action.equals(""))
			return false;

		if (tableName.equals("")) {
			return false;
		}

		if (getColumnsByTable(tableName).length != data.size()) {
			return false;
		}

		return true;
	}

	public List<String> getIpAddressList() {
		List<String> ipLst = new ArrayList<String>();
		Cursor cursor = db.rawQuery("select ns_ip from t_network_setting ",
				null);
		if (cursor != null) {
			while (cursor.moveToNext()) {
				String ipAddress = cursor.getString(cursor
						.getColumnIndex(DatabaseSchema.NetWorkSetting.NS_IP));

				ipLst.add(ipAddress);
			}
			cursor.close();
		}
		return ipLst;
	}
	
	public long ImageInsert(String upc,byte[] b,byte[] b2){
		ContentValues values = new ContentValues();
		values.put(DatabaseSchema.ItemPic.UPC, upc);
		values.put(DatabaseSchema.ItemPic.IP_IMAGE, b);
		values.put(DatabaseSchema.ItemPic.IP_IMAGE_SM, b2);
		long rowid = db.insert(DatabaseSchema.ItemPic.SCHEMA_NAME, null, values);
		return rowid;
	}
	
	public int ImageUpdate(String upc,byte[] b,byte[] b2){
		ContentValues values = new ContentValues();
		values.put(DatabaseSchema.ItemPic.IP_IMAGE, b);
		values.put(DatabaseSchema.ItemPic.IP_IMAGE_SM, b2);
		String[] args = {String.valueOf(upc)};
		return db.update(DatabaseSchema.ItemPic.SCHEMA_NAME, values, DatabaseSchema.ItemPic.UPC + " = ? ", args);
	}
	

	public void run(CommTask task) {
		
		List<String> records = task.getDbAction();
		extraFiles = task.getExtraFiles();
		
		if (records != null ) {
			for (int j = 0; j < records.size(); j++) {
				
				System.out.println("PROCESSOR -> data -> import data -> " + records.get(j));
				
				parseRecordString(records.get(j));
				
				System.out.println("PROCESSOR -> data -> parseRecord -> " + records.get(j));
				
				System.out.println("PROCESSOR -> data -> isvalid -> " + isValidAction());
				
				if (isValidAction()) {
					
					// System.out.println("PROCESSOR -> data -> commit -> "+tool.commit());
					// tool.commit();
					boolean succ = false;
					succ = commit();
					if (!succ) {
						System.out.println("PROCESSOR -> data -> commit -> not " + succ);
					}
				}
				
			}
			
		}

	}

	public List<String> getInventoryTerminalIP() {
		List<String> ipLst = new ArrayList<String>();
		Cursor cursor = db.rawQuery("select is_server_ip from t_inventory_setting ",
				null);
		if (cursor != null) {
			while (cursor.moveToNext()) {
				String ipAddress = cursor.getString(0);
				ipLst.add(ipAddress);
			}
			cursor.close();
		}
		return ipLst;
	}

	public void runRegKey(CommTask task) {
		// TODO Auto-generated method stub
		
			com.moleq.network.StoreSetting mStoreSetting =  task.getCompanyInfo().get(0);
			String code = task.getRegCode();
			System.out.println("PROCESSOR -> data ->code -> not " + code);
//			String macAddress = ServiceUtil.getMacAddress();
			System.out.println("----------------macAddress " + getMacAddress());
			
			String regcode = SecurityUtil.encryptToMD5(getMacAddress()+code);
			String name = mStoreSetting.getSs_name();
			String other_name = mStoreSetting.getSs_other_name();
			String address_1 = mStoreSetting.getSs_address_1();
			String address_2 = mStoreSetting.getSs_address_2();
			String city = mStoreSetting.getSs_city();
			String state = mStoreSetting.getSs_state();
			String zip = mStoreSetting.getSs_zip();
			String telephone = mStoreSetting.getSs_telephone();
			String fax = mStoreSetting.getSs_fax();
			String website = mStoreSetting.getSs_website();
			String business_name = mStoreSetting.getSs_business_name();
			
			//"Insert|t_item_setting|('000000000001','TEST ITEM 1 Tm
			// .',1,0,'A',10,'48',10.5,'','测试货品 1',
			// 2.88,1,0.0,'0','0','0','0','0','20120222020222','20121010073633','0','0','0','0','0','0','0',0,'0','0','0','0')";
			
			String codeStr = "INSERT|t_reg_key|('"+code+"','"+regcode+"')";
			parseRecordString(codeStr);
			if (isValidAction()) {
				
				// System.out.println("PROCESSOR -> data -> commit -> "+tool.commit());
				// tool.commit();
				boolean succ = false;
				succ = commit();
				if (!succ) {
					System.out.println("PROCESSOR -> data -> commit code -> not " + succ);
				}
			}
			
			System.out.println("PROCESSOR -> data ->run company info");
			String companyStr = "INSERT|t_store_setting|(1,'"+name+"','"+other_name+"','"+address_1+"','"+address_2+"','"+city+"','"+state+"','"+zip
								+"','"+telephone+"','"+fax+"','"+website+"','"+ServiceUtil.getCurrentDateTimeNow()+"','"+ServiceUtil.getCurrentDateTimeNow()+"','"+business_name+"')" ;
			parseRecordString(companyStr);
			if (isValidAction()) {
				
				// System.out.println("PROCESSOR -> data -> commit -> "+tool.commit());
				// tool.commit();
				boolean succ = false;
				succ = commit();
				if (!succ) {
					System.out.println("PROCESSOR -> data -> commit code -> not " + succ);
				}
			}
	}
		
}
